package com.sh.suhe.utildemos.utils.socket.entity;


import com.sh.suhe.utildemos.utils.JsonUtil;
import com.sh.suhe.utildemos.utils.LogUtil;

public class ResponsePacket {

    private static final String sCharset = "UTF-8";
    private Object data;
    private byte[] buffer;

    public byte[] getBuffer() {
        return buffer;
    }

    public void setBuffer(byte[] buffer) {
        this.buffer = buffer;

    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public <T> T  read(Class<T>  cls) {
        try {

            if (buffer != null){
                String ss = new String(buffer,sCharset);
                ss = ss.trim();
                data = JsonUtil.json2Object(ss,cls);
            }
        }catch (Exception e){
            LogUtil.e("ResponsePacket","对象解析错误"+cls);
        }
        return null;
    }
}
